home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / util / getutmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  952 b   |  59 lines

  1. #include "util.h"
  2. #include <utmp.h>
  3.  
  4. /* get informtion about who is logged in */
  5.  
  6. /* this is modeled after the getpw v7 set of routines */
  7.  
  8. LOCVAR char UTPATH[]  = "/etc/utmp";
  9. LOCVAR FILE *utmpfp = NULL;
  10. LOCVAR union tmpunion
  11. {
  12.     char        io[sizeof (struct utmp)];
  13.     struct utmp entry;
  14. }       utmp;
  15.  
  16. setutmp()
  17. {
  18.     if( utmpfp == NULL )
  19.         utmpfp = fopen( UTPATH, "r" );
  20.     else
  21.         rewind( utmpfp );
  22. }
  23.  
  24. endutmp()
  25. {
  26.     if( utmpfp != NULL ){
  27.         fclose( utmpfp );
  28.         utmpfp = NULL;
  29.     }
  30. }
  31.  
  32. struct utmp *
  33. getutmp()
  34. {
  35.     if (utmpfp == NULL) {
  36.         if( (utmpfp = fopen( UTPATH, "r" )) == NULL )
  37.             return(0);
  38.     }
  39.     if (fread (utmp.io, sizeof (struct utmp), 1, utmpfp) != 1)
  40.         return(0);
  41.     return(&utmp.entry);
  42. }
  43.  
  44. struct utmp *
  45. getutnam(name)
  46. char name[];
  47. {
  48.     register struct utmp *p;
  49.  
  50.     /*
  51.      * Both Dynix and Ultrix has the '8' hardwired into <utmp.h>.
  52.      * Hope this never breaks ;-) -- DSH
  53.      */
  54.     while( (p = getutmp()) && !equal(name, p->ut_name, 8))
  55.             ;
  56.  
  57.     return(p);
  58. }
  59.